﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCacheDServer.CacheStore;
using System.ServiceModel;
using System.Threading.Tasks;

namespace NCacheDServer
{

    public sealed class NCacheDServer : ICacheServer
    {

        private static Cache _cache = new Cache();


        public byte[] Get(string key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            var itemFromCache = _cache.GetItem(key);
            return itemFromCache;    

        }

        public void Put(string key, DateTime expiration, byte[] value)
        {
            if (key == null)
                throw new ArgumentNullException("key");
            if (value == null)
                throw new ArgumentNullException("value");

            Task.Factory.StartNew(()=>_cache.PutItem(key, expiration, value));
           
        }

        public void Delete(string key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            Task.Factory.StartNew(()=>_cache.RemoveItem(key));
        }

        public long GetSize()
        {
            var size = _cache.GetMaxSize();
            return size;

        }

    }
}
